package com.xwj.coupon.user.service.event.coupontemplate;

import cn.hutool.core.bean.BeanUtil;
import com.xwj.coupon.user.mq.message.CouponTemplateMessageBody;
import com.xwj.coupon.user.mq.producer.CreateCouponTemplateMqProducer;
import com.xwj.coupon.user.repository.mysql.entity.CouponTemplateDO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

/**
 * @Author: XuWenjie
 * @Date: 2025-08-13
 * @Description: MqProcessor
 */
@Component
@Slf4j
public class MqProcessor {
    @Autowired
    private CreateCouponTemplateMqProducer mqProducer;

    @EventListener
    public void process(CouponTemplateEvent event) {
        log.info("MqProcessor.process event:{}",event);
        CouponTemplateDO couponTemplate = event.getCouponTemplate();
        CouponTemplateMessageBody messageBody = BeanUtil.toBean(couponTemplate, CouponTemplateMessageBody.class);
        mqProducer.sendCreateMessageOrderly(messageBody,messageBody.getId().toString());
    }
}
